import app from "../../../../app"
import { player, wallet_key } from "../../../../model/fight/body/player"
import { template } from "../../../../shared/master/MsgAction"
import manage_user from "../../../model/manage/manage_user";

class lottery {
    logs: { name: string, duble: number, time: number }[] = []
    change:number = 0;
    constructor() {

    }
    start(p: player, gold: number) {
        // 1-100倍奖励 - 10%
        // 无奖励
        // 0.1-0.9倍奖励 50%
        let random = app.random(0, 100);
        let rang = 100;
        let _gold = 0;
        if(this.change > gold * 5){
            random = random - 30;
        }
        this.change -= 10;
        if (random < 10 && this.change > gold * 2) {
            rang = Math.ceil(app.random(1, app.random(10, app.random(1, 1000) / 10)));
            this.change -= Math.ceil(rang * gold);
            _gold = Math.ceil(rang * gold * 0.95);
            p.wallet_change(wallet_key.gold, _gold * 0.95)
            this.logs.push({ name: p.nickName, duble: rang, time: Date.now() })
            manage_user.sendAllMsg(template.default_none, `🎉恭喜${p.nickName}!在澳门·金币抽奖中获得${rang}倍奖励(💰+${_gold})!`)
        } else if (random < 80) {
            rang = app.random(1, 9) / 10;
            _gold = rang * gold;
            this.change += gold - _gold
            p.wallet_change(wallet_key.gold, _gold)
            p.sendMsg(template.default_none, `🎉恭喜您,在金币抽奖中获得${rang}倍奖励(💰+${app.BN(_gold)})!`)
        } else {
            p.sendMsg(template.default_none, '😭很遗憾,你抽中了空气')
            this.change += gold;
        }
    }
    look(p: player) {
        p.sendMsg(template.金币抽奖菜单, this.logs)
    }
}
export default new lottery()